home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Interfaces&Libraries / Universal / Interfaces / CIncludes / UnicodeUtilities.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-17  |  12.8 KB  |  329 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        UnicodeUtilities.h
  3.  
  4.      Contains:    Types, constants, prototypes for Unicode Utilities (Unicode input and text utils)
  5.  
  6.      Version:    Technology:    Allegro
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __UNICODEUTILITIES__
  18. #define __UNICODEUTILITIES__
  19.  
  20. #ifndef __MACTYPES__
  21. #include <MacTypes.h>
  22. #endif
  23.  
  24.  
  25.  
  26. #if PRAGMA_ONCE
  27. #pragma once
  28. #endif
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. #if PRAGMA_IMPORT
  35. #pragma import on
  36. #endif
  37.  
  38. #if PRAGMA_STRUCT_ALIGN
  39.     #pragma options align=mac68k
  40. #elif PRAGMA_STRUCT_PACKPUSH
  41.     #pragma pack(push, 2)
  42. #elif PRAGMA_STRUCT_PACK
  43.     #pragma pack(2)
  44. #endif
  45.  
  46. /*
  47.    -------------------------------------------------------------------------------------------------
  48.    CONSTANTS & DATA STRUCTURES
  49.    -------------------------------------------------------------------------------------------------
  50. */
  51. /*
  52.    -------------------------------------------------------------------------------------------------
  53.    UCKeyOutput & related stuff
  54.    The interpretation of UCKeyOutput depends on bits 15-14.
  55.    If they are 01, then bits 0-13 are an index in UCKeyStateRecordsIndex (resource-wide list).
  56.    If they are 10, then bits 0-13 are an index in UCKeySequenceDataIndex (resource-wide list),
  57.      or if UCKeySequenceDataIndex is not present or the index is beyond the end of the list,
  58.      then bits 0-15 are a single Unicode character.
  59.    Otherwise, bits 0-15 are a single Unicode character; a value of 0xFFFE-0xFFFF means no character
  60.      output.
  61.    UCKeyCharSeq is similar, but does not support indices in UCKeyStateRecordsIndex. For bits 15-14:
  62.    If they are 10, then bits 0-13 are an index in UCKeySequenceDataIndex (resource-wide list),
  63.      or if UCKeySequenceDataIndex is not present or the index is beyond the end of the list,
  64.      then bits 0-15 are a single Unicode character.
  65.    Otherwise, bits 0-15 are a single Unicode character; a value of 0xFFFE-0xFFFF means no character
  66.      output.
  67.    -------------------------------------------------------------------------------------------------
  68. */
  69.  
  70. typedef UInt16                             UCKeyOutput;
  71. typedef UInt16                             UCKeyCharSeq;
  72.  
  73. enum {
  74.     kUCKeyOutputStateIndexMask    = 0x4000,
  75.     kUCKeyOutputSequenceIndexMask = 0x8000,
  76.     kUCKeyOutputTestForIndexMask = 0xC000,                        /* test bits 14-15*/
  77.     kUCKeyOutputGetIndexMask    = 0x3FFF                        /* get bits 0-13*/
  78. };
  79.  
  80. /*
  81.    -------------------------------------------------------------------------------------------------
  82.    UCKeyStateRecord & related stuff
  83.    The UCKeyStateRecord information is used as follows. If the current state is zero,
  84.    output stateZeroCharData and set the state to stateZeroNextState. If the current state
  85.    is non-zero and there is an entry for it in stateEntryData, then output the corresponding
  86.    charData and set the state to nextState. Otherwise, output the state terminator from
  87.    UCKeyStateTerminators for the current state (or nothing if there is no UCKeyStateTerminators
  88.    table or it has no entry for the current state), then output stateZeroCharData and set the
  89.    state to stateZeroNextState.
  90.    -------------------------------------------------------------------------------------------------
  91. */
  92.  
  93.  
  94. struct UCKeyStateRecord {
  95.     UCKeyCharSeq                     stateZeroCharData;
  96.     UInt16                             stateZeroNextState;
  97.     UInt16                             stateEntryCount;
  98.     UInt16                             stateEntryFormat;
  99.                                                                 /* This is followed by an array of stateEntryCount elements*/
  100.                                                                 /* in the specified format. Here we just show a dummy array.*/
  101.     UInt32                             stateEntryData[1];
  102. };
  103. typedef struct UCKeyStateRecord            UCKeyStateRecord;
  104. /*
  105.    Here are the codes for entry formats currently defined.
  106.    Each entry maps from curState to charData and nextState.
  107. */
  108.  
  109. enum {
  110.     kUCKeyStateEntryTerminalFormat = 0x0001,
  111.     kUCKeyStateEntryRangeFormat    = 0x0002
  112. };
  113.  
  114. /*
  115.    For UCKeyStateEntryTerminal -
  116.    nextState is always 0, so we don't have a field for it
  117. */
  118.  
  119.  
  120. struct UCKeyStateEntryTerminal {
  121.     UInt16                             curState;
  122.     UCKeyCharSeq                     charData;
  123. };
  124. typedef struct UCKeyStateEntryTerminal    UCKeyStateEntryTerminal;
  125. /*
  126.    For UCKeyStateEntryRange -
  127.    If curState >= curStateStart and curState <= curStateStart+curStateRange,
  128.    then it matches the entry, and we transform charData and nextState as follows:
  129.    If charData < 0xFFFE, then charData += (curState-curStateStart)*deltaMultiplier
  130.    If nextState != 0, then nextState += (curState-curStateStart)*deltaMultiplier
  131. */
  132.  
  133. struct UCKeyStateEntryRange {
  134.     UInt16                             curStateStart;
  135.     UInt8                             curStateRange;
  136.     UInt8                             deltaMultiplier;
  137.     UCKeyCharSeq                     charData;
  138.     UInt16                             nextState;
  139. };
  140. typedef struct UCKeyStateEntryRange        UCKeyStateEntryRange;
  141. /*
  142.    -------------------------------------------------------------------------------------------------
  143.    UCKeyboardLayout & related stuff
  144.    The UCKeyboardLayout struct given here is only for the resource header. It specifies
  145.    offsets to the various subtables which each have their own structs, given below.
  146.    The keyboardTypeHeadList array selects table offsets that depend on keyboardType. The
  147.    first entry in keyboardTypeHeadList is the default entry, which will be used if the
  148.    keyboardType passed to UCKeyTranslate does not match any other entry - i.e. does not fall
  149.    within the range keyboardTypeFirst..keyboardTypeLast for some entry. The first entry
  150.    should have keyboardTypeFirst = keyboardTypeLast = 0.
  151.    -------------------------------------------------------------------------------------------------
  152. */
  153.  
  154. struct UCKeyboardTypeHeader {
  155.     UInt32                             keyboardTypeFirst;            /* first keyboardType in this entry*/
  156.     UInt32                             keyboardTypeLast;            /* last keyboardType in this entry*/
  157.     ByteOffset                         keyModifiersToTableNumOffset; /* required*/
  158.     ByteOffset                         keyToCharTableIndexOffset;    /* required*/
  159.     ByteOffset                         keyStateRecordsIndexOffset;    /* 0 => no table*/
  160.     ByteOffset                         keyStateTerminatorsOffset;    /* 0 => no table*/
  161.     ByteOffset                         keySequenceDataIndexOffset;    /* 0 => no table*/
  162. };
  163. typedef struct UCKeyboardTypeHeader        UCKeyboardTypeHeader;
  164.  
  165. struct UCKeyboardLayout {
  166.                                                                 /* header only; other tables accessed via offsets*/
  167.     UInt16                             keyLayoutHeaderFormat;        /* =kUCKeyLayoutHeaderFormat*/
  168.     UInt16                             keyLayoutDataVersion;        /* 0x0100 = 1.0, 0x0110 = 1.1, etc.*/
  169.     ByteOffset                         keyLayoutFeatureInfoOffset;    /* may be 0                                    */
  170.     ItemCount                         keyboardTypeCount;            /* Dimension for keyboardTypeHeadList[]        */
  171.     UCKeyboardTypeHeader             keyboardTypeList[1];
  172. };
  173. typedef struct UCKeyboardLayout            UCKeyboardLayout;
  174. /* -------------------------------------------------------------------------------------------------*/
  175.  
  176. struct UCKeyLayoutFeatureInfo {
  177.     UInt16                             keyLayoutFeatureInfoFormat;    /* =kUCKeyLayoutFeatureInfoFormat*/
  178.     UInt16                             reserved;
  179.     UniCharCount                     maxOutputStringLength;        /* longest possible output string*/
  180. };
  181. typedef struct UCKeyLayoutFeatureInfo    UCKeyLayoutFeatureInfo;
  182. /* -------------------------------------------------------------------------------------------------*/
  183.  
  184. struct UCKeyModifiersToTableNum {
  185.     UInt16                             keyModifiersToTableNumFormat; /* =kUCKeyModifiersToTableNumFormat*/
  186.     UInt16                             defaultTableNum;            /* For modifier combos not in tableNum[]*/
  187.     ItemCount                         modifiersCount;                /* Dimension for tableNum[]*/
  188.     UInt8                             tableNum[1];
  189.  
  190.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  191. };
  192. typedef struct UCKeyModifiersToTableNum    UCKeyModifiersToTableNum;
  193. /* -------------------------------------------------------------------------------------------------*/
  194.  
  195. struct UCKeyToCharTableIndex {
  196.     UInt16                             keyToCharTableIndexFormat;    /* =kUCKeyToCharTableIndexFormat*/
  197.     UInt16                             keyToCharTableSize;            /* Max keyCode (128 for ADB keyboards)*/
  198.     ItemCount                         keyToCharTableCount;        /* Dimension for keyToCharTableOffsets[] (usually 6 to 12 tables)*/
  199.     ByteOffset                         keyToCharTableOffsets[1];
  200.  
  201.                                                                 /* Each offset in keyToCharTableOffsets is from the beginning of the resource to a*/
  202.                                                                 /* table as follows:*/
  203.                                                                 /*    UCKeyOutput        keyToCharData[keyToCharTableSize];*/
  204.                                                                 /* These tables follow the UCKeyToCharTableIndex.*/
  205.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  206. };
  207. typedef struct UCKeyToCharTableIndex    UCKeyToCharTableIndex;
  208. /* -------------------------------------------------------------------------------------------------*/
  209.  
  210. struct UCKeyStateRecordsIndex {
  211.     UInt16                             keyStateRecordsIndexFormat;    /* =kUCKeyStateRecordsIndexFormat*/
  212.     UInt16                             keyStateRecordCount;        /* Dimension for keyStateRecordOffsets[]*/
  213.     ByteOffset                         keyStateRecordOffsets[1];
  214.  
  215.                                                                 /* Each offset in keyStateRecordOffsets is from the beginning of the resource to a*/
  216.                                                                 /* UCKeyStateRecord. These UCKeyStateRecords follow the UCKeyToCharTableIndex.*/
  217.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  218. };
  219. typedef struct UCKeyStateRecordsIndex    UCKeyStateRecordsIndex;
  220. /* -------------------------------------------------------------------------------------------------*/
  221.  
  222. struct UCKeyStateTerminators {
  223.     UInt16                             keyStateTerminatorsFormat;    /* =kUCKeyStateTerminatorsFormat*/
  224.     UInt16                             keyStateTerminatorCount;    /* Dimension for keyStateTerminators[] (# of nonzero states)*/
  225.     UCKeyCharSeq                     keyStateTerminators[1];
  226.  
  227.                                                                 /* Note: keyStateTerminators[0] is terminator for state 1, etc.*/
  228.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  229. };
  230. typedef struct UCKeyStateTerminators    UCKeyStateTerminators;
  231. /* -------------------------------------------------------------------------------------------------*/
  232.  
  233. struct UCKeySequenceDataIndex {
  234.     UInt16                             keySequenceDataIndexFormat;    /* =kUCKeySequenceDataIndexFormat*/
  235.     UInt16                             charSequenceCount;            /* Dimension of charSequenceOffsets[] is charSequenceCount+1*/
  236.     UInt16                             charSequenceOffsets[1];
  237.  
  238.                                                                 /* Each offset in charSequenceOffsets is in bytes, from the beginning of*/
  239.                                                                 /* UCKeySequenceDataIndex to a sequence of UniChars; the next offset indicates the*/
  240.                                                                 /* end of the sequence. The UniChar sequences follow the UCKeySequenceDataIndex.*/
  241.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  242. };
  243. typedef struct UCKeySequenceDataIndex    UCKeySequenceDataIndex;
  244. /* -------------------------------------------------------------------------------------------------*/
  245. /* Current format codes for the various tables (bits 12-15 indicate which table)*/
  246.  
  247.  
  248. enum {
  249.     kUCKeyLayoutHeaderFormat    = 0x1002,
  250.     kUCKeyLayoutFeatureInfoFormat = 0x2001,
  251.     kUCKeyModifiersToTableNumFormat = 0x3001,
  252.     kUCKeyToCharTableIndexFormat = 0x4001,
  253.     kUCKeyStateRecordsIndexFormat = 0x5001,
  254.     kUCKeyStateTerminatorsFormat = 0x6001,
  255.     kUCKeySequenceDataIndexFormat = 0x7001
  256. };
  257.  
  258.  
  259. /*
  260.    -------------------------------------------------------------------------------------------------
  261.    Constants for keyAction parameter in UCKeyTranslate() 
  262.    -------------------------------------------------------------------------------------------------
  263. */
  264.  
  265.  
  266. enum {
  267.     kUCKeyActionDown            = 0,                            /* key is going down*/
  268.     kUCKeyActionUp                = 1,                            /* key is going up*/
  269.     kUCKeyActionAutoKey            = 2,                            /* auto-key down*/
  270.     kUCKeyActionDisplay            = 3                                /* get information for key display (as in Key Caps)            */
  271. };
  272.  
  273. /*
  274.    -------------------------------------------------------------------------------------------------
  275.    Bit assignments & masks for keyTranslateOptions parameter in UCKeyTranslate() 
  276.    -------------------------------------------------------------------------------------------------
  277. */
  278.  
  279.  
  280. enum {
  281.     kUCKeyTranslateNoDeadKeysBit = 0                            /* Prevents setting any new dead-key states*/
  282. };
  283.  
  284.  
  285. enum {
  286.     kUCKeyTranslateNoDeadKeysMask = 1L << kUCKeyTranslateNoDeadKeysBit
  287. };
  288.  
  289. /*
  290.    -------------------------------------------------------------------------------------------------
  291.    FUNCTION PROTOTYPES
  292.    -------------------------------------------------------------------------------------------------
  293. */
  294.  
  295. EXTERN_API( OSStatus )
  296. UCKeyTranslate                    (UCKeyboardLayout *        keyLayoutPtr,
  297.                                  UInt16                 virtualKeyCode,
  298.                                  UInt16                 keyAction,
  299.                                  UInt32                 modifierKeyState,
  300.                                  UInt32                 keyboardType,
  301.                                  OptionBits             keyTranslateOptions,
  302.                                  UInt32 *                deadKeyState,
  303.                                  UniCharCount             maxStringLength,
  304.                                  UniCharCount *            actualStringLength,
  305.                                  UniChar                 unicodeString[]);
  306.  
  307.  
  308.  
  309. #if PRAGMA_STRUCT_ALIGN
  310.     #pragma options align=reset
  311. #elif PRAGMA_STRUCT_PACKPUSH
  312.     #pragma pack(pop)
  313. #elif PRAGMA_STRUCT_PACK
  314.     #pragma pack()
  315. #endif
  316.  
  317. #ifdef PRAGMA_IMPORT_OFF
  318. #pragma import off
  319. #elif PRAGMA_IMPORT
  320. #pragma import reset
  321. #endif
  322.  
  323. #ifdef __cplusplus
  324. }
  325. #endif
  326.  
  327. #endif /* __UNICODEUTILITIES__ */
  328.  
  329.